from pyvips import Image

icc_path = './icc/JapanColor2001Coated.icc'

bg_input_path = './input/KV_CMYK_red.tif'
benz_b_input_path = './input/benz-b.png'
benz_w_input_path = './input/benz-w.png'
logo_input_path = './input/logo.png'
# logo_input_path = './input/logo-alpha.tif'

benz_b_output_path = './output/benz-b.tif'
benz_w_output_path = './output/benz-w.tif'
logo_output_path = './output/logo.tif'
generated_output_path = './output/output.tif'

def convert():
    benz_b = Image.new_from_file(benz_b_input_path)
    benz_w = Image.new_from_file(benz_w_input_path)
    logo = Image.new_from_file(logo_input_path)
    benz_b = benz_b.icc_transform(icc_path)
    benz_w = benz_w.icc_transform(icc_path)
    logo = logo.icc_transform(icc_path)
    benz_b.write_to_file(benz_b_output_path, compression='none', Q=100, pyramid=True, bigtiff=True, depth='onepixel')
    benz_w.write_to_file(benz_w_output_path, compression='none', Q=100, pyramid=True, bigtiff=True, depth='onepixel')
    logo.write_to_file(logo_output_path, compression='none', Q=100, pyramid=True, bigtiff=True, depth='onepixel')


def compose(bg_path):
    bg = Image.new_from_file(bg_path)
    logo = Image.new_from_file(logo_output_path)
    logo = logo.resize(0.2)
    benz_b = Image.new_from_file(benz_b_output_path)
    benz_b = benz_b.resize(0.5)
    benz_w = Image.new_from_file(benz_w_output_path)
    benz_w = benz_w.resize(0.75)

    bg = bg.composite2(logo, 'over', x=bg.width / 2 - logo.width / 2, y=200, compositing_space='cmyk')
    bg = bg.composite2(benz_b, 'over', x=bg.width / 2 - benz_b.width / 2, y=700, compositing_space='cmyk')
    bg = bg.composite2(benz_w, 'over', x=bg.width / 2 - benz_w.width / 2, y=1000, compositing_space='cmyk')
    bg.write_to_file(generated_output_path, compression='none', Q=100, pyramid=True, bigtiff=True, depth='onepixel')

convert()

compose(bg_input_path)